import { CategoryService } from './category.service';
import { ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger';
import { Body, Controller, Get, Post, Query, Param } from '@nestjs/common';
import { CreateCategoryDto } from './dto/create-category.dto';

@ApiTags('文章分类')
@Controller('category')
export class CategoryController {
  constructor(private readonly categoryService: CategoryService) {}

  @ApiOperation({ summary: '创建分类' })
  @Post()
  async create(@Body() body: CreateCategoryDto) {
    return await this.categoryService.create(body.name);
  }

  @ApiOperation({ summary: '获取指定分类列表' })
  @Get('/byId')
  async findById(@Query('id') id: string) {
    return await this.categoryService.findById(id);
  }

  @ApiOperation({ summary: '获取全部分类列表' })
  @Get()
  @ApiQuery({ name: 'name', required: false, type: String })
  async findAll(
    @Query() query,
    @Query('pageSize') pageSize: number,
    @Query('pageNum') pageNum: number,
    @Query('name') name: string,
  ) {
    return await this.categoryService.findAll(query);
  }

  @ApiOperation({ summary: '获取全部分类列表和分类下的文章数' })
  @Get('/count')
  async findCategory() {
    return await this.categoryService.findCategory();
  }
}
